﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Application.Command.SheepChangeDormCommand;
using SheepStorage.API.Application.Command.TransferCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Controllers
{
	/// <summary>
	/// 后裔转种模块
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class ProgenyTransferController : ControllerBase
	{
		/// <summary>
		/// Service
		/// </summary>
	   private	 readonly IProgenyTransferService service;



		private readonly IMapper mapper;


		private readonly IMediator mediator;

		public ProgenyTransferController(IProgenyTransferService service, IMediator mediator, IMapper mapper)
		{
			this.service = service;
			this.mediator = mediator;
			this.mapper = mapper;
		}







		/// <summary>
		/// 后裔转种列表
		/// </summary>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Results<PageOutput<ProgenyTransfer>>> GetProgenyTransfers(ProgenyTransferShowCommand command)
		{

			return await mediator.Send(command);

		}


        /// <summary>
        /// 后裔转种添加 
        /// </summary>
        /// <param name="progenyTransfer"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddProgenyTransfer(ProgenyTransferAddCommand command)
        {

            return await mediator.Send(command);

        }
  

		/// <summary>
		/// 后裔转种逻辑删除/批量删除
		/// </summary>
		/// <param name="TransferId"></param>
		/// <returns></returns>
		[HttpPost]
		 
		public async Task<Results<int>> DeleteProgenyTransfer(ProgenyTransferDeleteCommand command)
		{

			return await mediator.Send(command);

		}

		/// <summary>
		/// 根据id反填信息
		/// </summary>
		/// <param name="TransferId"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<Results<ProgenyTransfer>> GetProgenyTransferById(int TransferId)
		{
			var res = await service.GetProgenyTransferById(TransferId);
			return Results<ProgenyTransfer>.DataResult(res);
		}



		/// <summary>
		/// 根据id修改信息
		/// </summary>
		/// <param name="model"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Results<int>> UpdateProgenyTransfer(ProgenyTransfer model)
		{
			var res = await service.UpdateProgenyTransfer(model);
			return Results<int>.DataResult(res);
		}

	}
}
